package HTMLParser.HTMLTag;

import Parser.Token;

/*******************************************************************************
 * This class simply represents a Table tag. It will extract the desired border
 * size value from within the tag (if it is there), and store it in a variable.
 * @author James Johnstone
 * @version FINAL
 *******************************************************************************/
public class Table extends Tag {

    private int borderSize;

    /*******************************************************************************
     * Constructor for the Table class. Takes one variable which is a Token
     * representing the HTML Tag (example: <TABLE BORDER="5">). It then
     * extracts the desired border size and stores it appropriately.
     * @param t A Token representing a HTML TABLE tag.
     *******************************************************************************/
    public Table(Token t) {
        super(t, (t.getToken().length() > 5 ? t.getToken().substring(0, 5) : t.getToken()));
        setBorderSize(t);
    }

    private void setBorderSize(Token t) {
        String tokenString = t.getToken().toLowerCase();
        if (tokenString.contains("border=" + '"')) {
            int first = tokenString.indexOf("border=" + '"') + 8;
            int last = tokenString.indexOf("" + '"', first);
            borderSize = Integer.parseInt(tokenString.substring(first, last));
        } else {
            borderSize = 0;
        }
    }

    /***************************************************************************
     * This method returns the border size of the table tag it represents.
     * @return An integer representing the border size.
     ***************************************************************************/
    public int getBorderSize() {
        return borderSize;
    }
}
